//
//  MyHeaderView.m
//  SpeechRecognition
//
//  Created by 张云江 on 2019/10/12.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "MyHeaderView.h"

@implementation MyHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView
{
    UIImageView *bgImageView = [[UIImageView alloc] init];
    [self addSubview:bgImageView];
    bgImageView.sd_layout.spaceToSuperView(UIEdgeInsetsZero);
    
    UIImageView *userIcon = [[UIImageView alloc]init];
    userIcon.image = [UIImage imageNamed:@"user_icon"];
    [bgImageView addSubview:userIcon];
    userIcon.sd_layout
    .leftEqualToView(bgImageView)
    .centerYEqualToView(bgImageView)
    .heightIs(kRatio(101))
    .widthIs(kRatio(101));
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [bgImageView addSubview:titleLabel];
    titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:kRatio(21)];
    titleLabel.textColor = kUIColorFromRGB(0x000000);
    titleLabel.numberOfLines = 0;
    titleLabel.sd_layout
    .centerYEqualToView(userIcon)
    .leftSpaceToView(userIcon, kRatio(1))
    .rightSpaceToView(bgImageView, kRatio(23))
    .heightIs(kRatio(100));
    if (kVipBool) {
        NSString *date = [[NSUserDefaults standardUserDefaults] objectForKey:@"Date"];
        if (!date) {
            NSDate *newDate = [NSDate new];
            NSDateFormatter *date_formatter = [[NSDateFormatter alloc] init];
            [date_formatter setDateFormat:@"yyyy-MM-dd"];
            date = [date_formatter stringFromDate:newDate];
        }
        titleLabel.text = [NSString stringWithFormat:@"到期日期\n%@",date];
    } else {
        titleLabel.text = [NSString stringWithFormat:@"欢迎使用\n证件照相机"];
    }
}
@end
